/*
 * @Author: your name
 * @Date: 2021-05-10 14:35:29
 * @LastEditTime: 2021-05-10 20:38:41
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \after-end\app\service\newHouse.js
 */
"use strict";

const Service = require("egg").Service;

class newHouseService extends Service {
  //列表查看
  async newHouseList(pageIndex, pageSize) {
    const total = await this.app.mysql.select("newHouse");
    // console.log((pageIndex - 1) * pageSize * 1, pageIndex * pageSize * 1);
    const res = await this.app.mysql.select("newHouse", {
      // 搜索 post 表
      limit: Number(pageSize * 1), // 返回数据量
      offset: Number((pageIndex - 1) * pageSize * 1), // 数据偏移量
    });
    const newRes = res.map((item) => {
      item.flag ? (item.flag = true) : (item.flag = false);
      return item;
    });
    return { total, newRes };
  }
  // 添加
  async newHouseAdd(
    name,
    word,
    region,
    mianji,
    price,
    type,
    company,
    RoleName,
    HouseType,
    phone,
    ip,
    flag,
    names,
    metro,
    num,
    time
  ) {
    const { app } = this;
    await app.mysql.insert("newHouse", {
      name: name,
      ip: ip,
      word: word,
      region: region,
      mianji: mianji,
      price: price,
      type: type,
      company: company,
      RoleName: RoleName,
      HouseType: HouseType,
      phone: phone,
      flag: flag,
      names: names,
      metro: metro,
      num: num,
      time: time,
    });
    return true;
  }
  // 删除
  async newHouseDel(id) {
    const { app } = this;
    await app.mysql.delete("newHouse", {
      id: id,
    });
    return true;
  }
  // 编辑
  async newHouseSet(obj) {
    const { app } = this;

    await app.mysql.update("newHouse", obj);
    return true;
  }
}
module.exports = newHouseService;
